package com.ojoin.trade.supplyloan_core.web.service.impl;

import java.util.HashMap;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.ojoin.trade.common.web.service.impl.BaseServiceImpl;
import com.ojoin.trade.supplyloan_core.web.dao.TbSlPlatformInfoDao;
import com.ojoin.trade.supplyloan_core.web.domain.TbSlPlatformInfo;
import com.ojoin.trade.supplyloan_core.web.service.TbSlPlatformInfoService;
 
@Service
public class TbSlPlatformInfoServiceImpl extends
	BaseServiceImpl<TbSlPlatformInfo> implements TbSlPlatformInfoService {
  
	@Autowired
	private TbSlPlatformInfoDao dao;
	private Logger log = LoggerFactory
			.getLogger(TbSlPlatformInfoServiceImpl.class);

	@Override
	protected TbSlPlatformInfoDao getBaseDao() {
		return dao;
	}
	
	@Cacheable(value = "enumCache",key="#root.targetClass +#root.methodName")
	@Override
	public List<TbSlPlatformInfo> queryAllcache() {
		List<TbSlPlatformInfo> li = this.getBaseDao().selectAll();
		if (li == null || li.size() == 0)
			return null;
		
		return li ;
	}
	
	@Cacheable(value = "enumCache",key="#root.targetClass +#root.methodName")
	@Override
	public HashMap<Integer, TbSlPlatformInfo> getPlatformInfoIDMapCache() {
		HashMap<Integer, TbSlPlatformInfo> platformInfoIDMap = new HashMap<Integer, TbSlPlatformInfo>();
		
		List<TbSlPlatformInfo> list = queryAllcache();
		for(TbSlPlatformInfo info : list) {
			platformInfoIDMap.put(info.getId(), info);
		}
		
		return platformInfoIDMap;
	}

	@Cacheable(value = "enumCache",key="#root.targetClass +#root.methodName")
	@Override
	public HashMap<String, TbSlPlatformInfo> getPlatformInfoNameMapCache() {
		HashMap<String, TbSlPlatformInfo> platformInfoNameMap = new HashMap<String, TbSlPlatformInfo>();
		
		List<TbSlPlatformInfo> list = queryAllcache();
		for(TbSlPlatformInfo info : list) {
			platformInfoNameMap.put(info.getPlatformName(), info);
		}
		
		return platformInfoNameMap;
	}
	
	@Override
	public TbSlPlatformInfo queryByName(String name) {
		HashMap<String,TbSlPlatformInfo> mapCache = getPlatformInfoNameMapCache();
		return mapCache.get(name);
	} 
	
}
